package com.dream.dreamweb.config;

import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.PropertySource;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.jdbc.datasource.DriverManagerDataSource;

import javax.sql.DataSource;

/**
 * @author ：tiger.
 * @date ：2021/10/14 20:48
 */
@Configuration
@PropertySource("classpath:db.properties")
@EnableConfigurationProperties(DbConfig.DbProperties.class)
public class DbConfig {

//	@Bean
//	public DataSource dataSource(DbProperties properties) {
//		DriverManagerDataSource dataSource = new DriverManagerDataSource();
//		dataSource.setUrl(properties.getUrl());
//		dataSource.setUsername(properties.getUsername());
//		dataSource.setDriverClassName(properties.getDriver());
//		dataSource.setPassword(properties.getPassword());
//		return dataSource;
//	}
//
//	@Bean
//	public JdbcTemplate jdbcTemplate(DataSource dataSource) {
//		return new JdbcTemplate(dataSource);
//	}


	@ConfigurationProperties(prefix = "db")
	static class DbProperties {

		private String username;

		private String password;

		private String url;

		private String driver;

		public String getUsername() {
			return username;
		}

		public void setUsername(String username) {
			this.username = username;
		}

		public String getPassword() {
			return password;
		}

		public void setPassword(String password) {
			this.password = password;
		}

		public String getUrl() {
			return url;
		}

		public void setUrl(String url) {
			this.url = url;
		}

		public String getDriver() {
			return driver;
		}

		public void setDriver(String driver) {
			this.driver = driver;
		}
	}
}
